package com.singlemusic.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.*;

@Controller
@RequestMapping("/testlrc")
public class LrcController {
	
	@RequestMapping("/getLrc")
	public void getLrc(HttpServletRequest request, HttpServletResponse response){
		response.setContentType("text/plain; charset=utf-8");
		String path = request.getSession().getServletContext().getRealPath("lrc");
		
		InputStream is = null;
		OutputStream os = null;
		try {
			is = new FileInputStream(path+"/ai_la_la.lrc");
			byte[] buffer = new byte[1024];
			int len = 0;
			os = response.getOutputStream();
			
			while((len=is.read(buffer))!=-1){
				os.write(buffer, 0, len);
			}
			os.flush();
			os.close();
			is.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

}
